<?
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }
$sql = $db->Query("SELECT id,points,s_name FROM `soundcloud` WHERE `user`='".$data['id']."'");
$data2 = $db->FetchArray($sql);
$error = 1;

if(isset($_POST['add'])){
	$coins = $db->EscapeString($_POST['coins']);
	
	if($coins <= -1 || $coins == 0){
		$mesaj = '<div class="msg"><div class="error">Error! Enter a Number!</div></div>';
	}elseif(!is_numeric($coins)){
		$mesaj = '<div class="msg"><div class="error">Error! Enter a Number</div></div>';
	}elseif($coins > $data['coins']){
		$mesaj = '<div class="msg"><div class="error">Error! You do not have enough Coins!</div></div>';
	}elseif($data2['id'] != "" && $data['id'] != ""){
		$db->Query("UPDATE `soundcloud` SET `points`=`points`+'".$coins."' WHERE `id`='".$data2['id']."'");
		$db->Query("UPDATE `users` SET `coins`=`coins`-'".$coins."' WHERE `id`='".$data['id']."'");
		$mesaj = '<div class="msg"><div class="success">Coins Assigned!</div></div>';
		$error = 0;
	}
}
if($data2['id'] == ""){
redirect('index.php');
}
echo $mesaj;
?>
<p>There are <b><?=($error == 0 ? ($_POST['coins']+$data2['points']) : $data2['points'])?></b> coins assigned to the Campaign <b><?=$data2['s_name']?></b><br></p>
<form method="post">
	<fieldset>
		<p>
		<label>Add more Coins!</label>
		<input type="text" class="text big" name="coins" value="10">
		</p>
		<p>
		<input type="submit" class="button gray small" name="add" value="Submit">
		</p>
	</fieldset>
</form>